package com.kcyu.sfherp.dto;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

@Data
public class QueryCondition {

    private String content;
    private String keyword;
    private String relate;

    public <T> QueryWrapper<T> getQueryWrapper(List<QueryCondition> queryConditions, Class<T> targetClass) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
        for (int i = 0; i < queryConditions.size(); i++) {
            QueryCondition queryCondition = queryConditions.get(i);
            if (queryCondition.getRelate().equals("eq")) {
                queryWrapper.eq(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("like")) {
                queryWrapper.like(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("ge")) {
                queryWrapper.ge(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("le")) {
                queryWrapper.le(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("gt")) {
                queryWrapper.gt(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("lt")) {
                queryWrapper.lt(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("ne")) {
                queryWrapper.ne(queryCondition.getContent(), queryCondition.getKeyword());
            } else if (queryCondition.getRelate().equals("isNull")) {
                queryWrapper.isNull(queryCondition.getContent());
            } else if (queryCondition.getRelate().equals("isNotNull")) {
                queryWrapper.isNotNull(queryCondition.getContent());
            } else if (queryCondition.getRelate().equals("orderByAsc")) {
                queryWrapper.orderByAsc(queryCondition.getContent());
            } else if (queryCondition.getRelate().equals("orderByDesc")) {
                queryWrapper.orderByDesc(queryCondition.getContent());
            }
        }

        return queryWrapper;
    }

}
